/**
 * 
 */
package com.kylin.frame.core.filter;

import com.jfinal.config.Constants;
import com.jfinal.config.Handlers;
import com.jfinal.config.Interceptors;
import com.jfinal.config.JFinalConfig;
import com.jfinal.config.Plugins;
import com.jfinal.config.Routes;
import com.jfinal.plugin.activerecord.ActiveRecordPlugin;
import com.jfinal.plugin.c3p0.C3p0Plugin;
import com.jfinal.plugin.spring.SpringPlugin;
import com.kylin.erp.dbmodel.TCompany;
import com.kylin.erp.dbmodel.TDepts;
import com.kylin.erp.dbmodel.TMembers;
import com.kylin.erp.dbmodel.TMenuResources;
import com.kylin.erp.oa.system.controller.CommonController;
import com.kylin.erp.oa.system.controller.MemberController;
import com.kylin.erp.oa.system.controller.MenuController;
import com.kylin.erp.oa.system.controller.OrgnController;
import com.kylin.frame.core.activerecord.CaseInsensitiveContainerFactory;
import com.kylin.frame.core.controller.StaticController;
import com.kylin.frame.core.handler.CommonAttrHandler;
import com.kylin.frame.core.interceptor.AuthInterceptor;

/**
 * 应用加载控制类
 * 
 * @author huxiang
 * 
 */
public class UdfContextConfig extends JFinalConfig {

	/**
	 * 
	 */
	public UdfContextConfig() {
		// TODO Auto-generated constructor stub
	}

	/*
	 * (non-Javadoc)
	 * 
	 * @see
	 * com.jfinal.config.JFinalConfig#configConstant(com.jfinal.config.Constants
	 * )
	 */
	@Override
	public void configConstant(Constants me) {
		me.setDevMode(true);
		me.setBaseViewPath("/WEB-INF/html");
	}

	/*
	 * (non-Javadoc)
	 * 
	 * @see com.jfinal.config.JFinalConfig#configRoute(com.jfinal.config.Routes)
	 */
	@Override
	public void configRoute(Routes me) {
		me.add("/static", StaticController.class, "/");
		me.add("/", CommonController.class, "/");
		me.add("/system/menu", MenuController.class, "/system/menu");
		me.add("/system/orgn", OrgnController.class, "/system/orgn");
		me.add("/system/member", MemberController.class, "/system/member");
	}

	/*
	 * (non-Javadoc)
	 * 
	 * @see
	 * com.jfinal.config.JFinalConfig#configPlugin(com.jfinal.config.Plugins)
	 */
	@Override
	public void configPlugin(Plugins me) {
		me.add(new SpringPlugin());
		C3p0Plugin cp = new C3p0Plugin(
				"jdbc:mysql://localhost:3306/udf?useUnicode=true&characterEncoding=utf-8",
				"root", "huxiang");
		me.add(cp);
		ActiveRecordPlugin arp = new ActiveRecordPlugin(cp);
		arp.setContainerFactory(new CaseInsensitiveContainerFactory());// 大小写不敏感
		me.add(arp);
		arp.addMapping("t_companys", "id_", TCompany.class);
		arp.addMapping("t_menu_resources", "id_", TMenuResources.class);
		arp.addMapping("t_depts", "id_", TDepts.class);
		arp.addMapping("t_members", "id_", TMembers.class);
	}

	/*
	 * (non-Javadoc)
	 * 
	 * @see com.jfinal.config.JFinalConfig#configInterceptor(com.jfinal.config.
	 * Interceptors)
	 */
	@Override
	public void configInterceptor(Interceptors me) {

		me.add(new AuthInterceptor());
	}

	/*
	 * (non-Javadoc)
	 * 
	 * @see
	 * com.jfinal.config.JFinalConfig#configHandler(com.jfinal.config.Handlers)
	 */
	@Override
	public void configHandler(Handlers me) {
		me.add(new CommonAttrHandler());

	}

}
